package com.shengwei.truck.driver.vm;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.shengwei.truck.driver.bean.Result;
import com.shengwei.truck.driver.bean.task.JsonSearchUserData;
import com.shengwei.truck.driver.model.DataSource;
import com.shengwei.truck.driver.model.Repository;

public class ShareForwardViewModel extends ViewModel {
    private Repository mRepository; //M层引用
    MutableLiveData<Result<JsonSearchUserData>> mSearchUserLiveData = new MutableLiveData<>();
    MutableLiveData<Result<String>> mShareForwardLiveData = new MutableLiveData<>();

    public ShareForwardViewModel(Repository repository) {
        mRepository = repository;
    }
    public ShareForwardViewModel() {
        mRepository = Repository.getInstance(DataSource.getSingleInstance());
    }

    public MutableLiveData<Result<JsonSearchUserData>> getSearchUserLiveData() {
        return mSearchUserLiveData;
    }

    public MutableLiveData<Result<String>> getShareForwardLiveData() {
        return mShareForwardLiveData;
    }

    /**
     * 根据手机号查找用户
     * @param mobileNum
     */
    public void searchUserByMobile(String mobileNum,String taskId) {
        mRepository.searchUserByMobile(mobileNum,taskId,mSearchUserLiveData);
    }

    /**
     * 分享或转派任务
     *
     * @param taskId： 要转派（共享）的任务ID
     * @param targetUserId：转派（共享）给的目标用户
     * @param shareOrForward : 1转派； 2共享
     */
    public void shareForward(String taskId, String targetUserId, int shareOrForward) {
        mRepository.shareForward(taskId,targetUserId,shareOrForward,mShareForwardLiveData);
    }
}
